using UnityEngine;
using UnityEngine.UI;

//有这行生成的脚本都是UTF-8形式的
namespace MyGame
{
    public class BackGroundUI :BaseUI<BackGroundUI>
    {
        public const string title1 = "黑方步数:";
        public const string title2 = "白方步数:";
        public const string title3 = "当前执方:";

        public const string playName1 = "玩家1";
        public const string playName2 = "玩家2";
        public const string playName3 = "电脑AI";
 
        public RectTransform top;
        public RectTransform middle;
        public RectTransform bottom;

        [Header("黑方姓名")]
        public Text black_name;
        [Header("白方姓名")]
        public Text white_name;
        [Header("黑方步数")]
        public Text black_index;
        [Header("白方步数")]
        public Text white_index;
       

        [Header("当前执行")]
        public Text executor_play;

        [Header("开始游戏")]
        public MyButton startGame_button;

        [Header("悔棋")]
        public MyButton takeBack_button;

      

        protected override void Awake()
        {
            //注册菜单
            UIManager.Instance.RegisterMenu(uIType, gameObject);

            RegisterAction();
        }

        private void OnDisable()
        {
            black_name.text = null;
            white_name.text = null;
            black_index.text = null;
            white_index.text = null;
            executor_play.text = null;
        }

        private void Start()
        {
            Hide();
        }

        public void Init()
        {
            takeBack_button.gameObject.SetActive(false);
            startGame_button.gameObject.SetActive(true);
        }

        void RegisterAction()
        {
            startGame_button.myAction_Click += (() =>
            {
                takeBack_button.gameObject.SetActive(true);
                GameManager.Instance.StartGame();
                startGame_button.gameObject.SetActive(false);
            });

            startGame_button.myAction_Enter += () =>
            {
                startGame_button.transform.localScale = Vector3.one * 1.2f;
                startGame_button.myImage.color = Color.blue;
            };

            startGame_button.myAction_Exit += () =>
            {
                startGame_button.transform.localScale = Vector3.one * 1;
                startGame_button.myImage.color = Color.black;
            };

            takeBack_button.myAction_Click += (() =>
            {
                if (GameManager.Instance.isGaming)
                {
                    Debug.Log("悔棋");
                    ChessManager.Instance.LoseNumber();
                }           
            });

            takeBack_button.myAction_Enter += () =>
            {
                takeBack_button.transform.localScale = Vector3.one * 1.2f;
                takeBack_button.myImage.color = Color.blue;
            };

            takeBack_button.myAction_Exit += () =>
            {
                takeBack_button.transform.localScale = Vector3.one * 1;
                takeBack_button.myImage.color = Color.black;
            };
        }

        public void UpdateTextInit(string _black_Name = "",string _white_Name = "",string _black_Index="", string _white_Index = "",string executor_Play="")
        {
            black_name.text = _black_Name;
            white_name.text = _white_Name;
            black_index.text = _black_Index;
            white_index.text = _white_Index;
            executor_play.text = executor_Play; 
        }

        public void UpdateTextBlack(int black_new_index)
        {
            black_index.text = title1 + black_new_index.ToString();
        }

        public void UpdateTextWhite(int white_new_index)
        {
            white_index.text = title2 + white_new_index.ToString();
        }

        public void ChangeExecutor(string executor)
        {
            executor_play.text = title3 + executor;
        }

        public void GamaOver()
        {
            takeBack_button.gameObject.SetActive(false);    
        }

        private void OnDestroy()
        {
            //注销菜单
            UIManager.Instance.UnregisterMenu(uIType);
        }
    }   
}


